<script setup>
import { Edit, Delete } from '@element-plus/icons-vue'
import { ref } from 'vue'
import { artDelChannelServices, artGetChannelsServices } from '@/api/article'
import ChannelEdit from './components/ChannelEdit.vue'
const dialog = ref()
const channelList = ref([])
const loading = ref(true)
const getChannelList = async () => {
    const res = await artGetChannelsServices()
    channelList.value = res.data.data
    loading.value = false
}
getChannelList()
const onEditChannel = (row, $index) => {
    dialog.value.open(row)
}
const onDelChannel = async (row, $index) => {
    await ElMessageBox.confirm('你确定要删除吗', '删除确认', {
        confirmButtonText: '确认',
        cancelButtonText: '取消',
        type: 'warning'
    })
    await artDelChannelServices(row.id)
    ElMessage.success('删除成功')
    getChannelList()
}
const onAddChannel = () => {
    dialog.value.open({})
}
</script>

<template>
    <page-container title="文章分类">
        <template #extra>
            <el-button type="primary" @click="onAddChannel"> 添加分类 </el-button>
        </template>
        <el-table v-loading="loading" :data="channelList">
            <el-table-column type="index" label="序号" width="100"></el-table-column>
            <el-table-column prop="cate_name" label="分类名称"></el-table-column>
            <el-table-column prop="cate_alias" label="分类别名"></el-table-column>
            <el-table-column label="操作" width="100">
                <template #default="{ row, $index }">
                    <el-button @click="onEditChannel(row, $index)" type="primary" :icon="Edit" circle></el-button>
                    <el-button @click="onDelChannel(row, $index)" type="danger" :icon="Delete" circle></el-button>
                </template>
            </el-table-column>
            <template #empty> <el-empty description="没有数据哦" /> </template
        ></el-table>

        <ChannelEdit ref="dialog" @success="getChannelList"></ChannelEdit>
    </page-container>
</template>

<style lang="scss" scoped></style>
